package leetcode.code;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

public class Solution520 implements IDebug {
	public boolean detectCapitalUse(String word) {
		if (word.length() == 1)
			return true;
		char[] words = word.toCharArray();
		int len = words.length;
		// 第一个字符是小写 或者 第一个字符大写第二个小写的时候，后续都要是小写
		if (this.lowercase(words[0]) || this.lowercase(words[1])) {
			for (int i = 1; i < len; i++) {
				if (!this.lowercase(words[i])) {// 出现大写就错了
					return false;
				}
			}
		} else {
			// 前两个都是大写，后续出现小写就错了
			for (int i = 2; i < len; i++) {
				if (this.lowercase(words[i])) {
					return false;
				}
			}
		}
		return true;
	}

	// 是小写字母吗
	private boolean lowercase(char c) {
		return c >= 'a' && c <= 'z';
	}

	@Override
	public void debug1() {
		String word = "USA";
		boolean e = true;
		boolean r = this.detectCapitalUse(word);
		HelpDebug.compare(e, r);
	}

	@Override
	public void debug2() {
		String word = "FlaG";
		boolean e = false;
		boolean r = this.detectCapitalUse(word);
		HelpDebug.compare(e, r);
	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug4() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution520 so = new Solution520();
		so.debug1();
		so.debug2();

	}

}
